package org.hry.netty.protobuf;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.concurrent.TimeUnit;

/**
 * @Desc
 * @Author houry
 * @Date 2021/2/20 15:46
 **/
public class ProtoBufClientHandler extends SimpleChannelInboundHandler<BarrageProto.Barrage> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, BarrageProto.Barrage msg) throws Exception {

    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        BarrageProto.Barrage.Builder builder = BarrageProto.Barrage.newBuilder();
//        builder.setMsgType("test");
//        ctx.channel().eventLoop().scheduleAtFixedRate(() -> ctx.writeAndFlush(builder), 2, 2, TimeUnit.SECONDS);
        TestProto.Test.Builder builder = TestProto.Test.newBuilder();
        builder.setTestMsgType("lky");
//        ctx.channel().eventLoop().scheduleAtFixedRate(() -> ctx.writeAndFlush(builder), 2, 2, TimeUnit.SECONDS);
        ctx.channel().writeAndFlush(builder);
    }
}
